//
//  JZHAuctionCell.m
//  极致荟
//
//  Created by mac on 14-4-30.
//  Copyright (c) 2014年 mac. All rights reserved.
//

#import "JZHAuctionCell.h"

@implementation JZHAuctionCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        //加载nib
        NSArray *arrayOfViews = [[NSBundle mainBundle] loadNibNamed:@"JZHAuctionCell" owner:self options:nil];
        if (arrayOfViews.count < 1) {
            return nil;
        }
        if (![[arrayOfViews objectAtIndex:0] isKindOfClass:[JZHAuctionCell class]]) {
            return nil;
        }
        
        self = [arrayOfViews objectAtIndex:0];
    }
    self.timerun=NO;
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)adddata:(JZHCommodity *)conmmodity
{
    self.meony.text=[NSString stringWithFormat:@"当前价格 %.2f元", conmmodity.paprice];
    self.spname.text=conmmodity.name;
    self.comm=conmmodity;
    if(!self.timerun)
    {
        NSTimer *time=[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timeaout:) userInfo:[[NSDictionary alloc] initWithObjectsAndKeys:conmmodity,@"time", nil] repeats:YES];
    }
    
}

- (void)timeaout:(NSTimer *)time
{
    int  times=self.comm.surplustime-1;
    NSString *str=@"";
    int s=times/3600;
    int f=(times-s*
           3600)/60;
    int m=times-(s*3600+f*60);
    self.comm.surplustime=times;
    
    if(s<10)
    {
        str=[str stringByAppendingFormat:@"剩余时间 0%d:",s];
    }else
    {
        str=[str stringByAppendingFormat:@"剩余时间 %d:",s];
    }
    if(f<10)
    {
        str=[str stringByAppendingFormat:@"0%d:",f];
    }else
    {
        str=[str stringByAppendingFormat:@"%d:",f];
    }
    if(m<10)
    {
        str=[str stringByAppendingFormat:@"0%d",m];
    }else
    {
        str=[str stringByAppendingFormat:@"%d",m];
    }
    
    self.endtime.text=str;
    
    
}
@end
